//
//  HMElementSortVC.m
//  test5
//
//  Created by edz on 2017/11/7.
//  Copyright © 2017年 edz. All rights reserved.
//

#import "HMElementSortVC.h"
#import "HMElementSortCell.h"
@interface HMElementSortVC () <UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, copy) NSMutableArray *dataArray;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *courseNameLabel;



@end

@implementation HMElementSortVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configTableView];
    self.title = @"要素排序";
    self.courseNameLabel.text = _name;
}

- (void)configTableView {
    
    self.edgesForExtendedLayout = UIRectEdgeNone;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.tableView registerNib:[UINib nibWithNibName:@"HMElementSortCell" bundle:nil] forCellReuseIdentifier:@"HMElementSortCellId"];
    
    
}

-(NSMutableArray *)dataArray {
    if (_dataArray == nil) {
        _dataArray = [NSMutableArray new];
    }
    return _dataArray;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return  _dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *tDict = _dataArray[indexPath.row];
    HMElementSortCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HMElementSortCellId" forIndexPath:indexPath];
    cell.levelLabel.text = [NSString stringWithFormat:@"%@",tDict[@"commentCount"]];
    cell.contenLabel.text = tDict[@"setCourseComment"][@"content"];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

#pragma mark - Setter

- (void)setLessonId:(NSString *)lessonId {
    _lessonId = lessonId;
    [self setNetWork];
}

//-(void)setName:(NSString *)name {
//    _name = name;
//
//}

#pragma mark - Net

- (void)setNetWork{
  //http://192.168.0.113:8080/StarShine/ys/resource.do?action=getElementByLessinId&&lessonId=649
    NSString *url = [NSString stringWithFormat:@"resource.do?action=getElementByLessinId&&lessonId=%@",self.lessonId];

    NSLog(@"%@ %@",LLBaseURL(url),[AccountTool shareAccountTool].currentAccount.authCode);
    
//    [SVProgressHUD setDefaultStyle:(SVProgressHUDStyleCustom)];
//    [SVProgressHUD  setBackgroundColor:ColorRGB(4, 4, 4)];
//    [SVProgressHUD setForegroundColor:[UIColor whiteColor]];
//    [SVProgressHUD showWithStatus:LLLoading];
    
    [NetManager Get:LLBaseURL(url) Auth:YES Params:nil Success:^(id Obj) {
        [SVProgressHUD dismiss];
        if ([[Obj valueForKey:@"code"] integerValue] == 1000) {
            
            NSArray *tArray = [Obj valueForKey:@"t"];
            _dataArray = tArray.copy;
            NSLog(@"%@",[Obj valueForKey:@"t"]);
            [self.tableView reloadData];
        }
   
    } Fail:^(NSError *Error) {
        [MBProgressHUD showError:NetErr];
    }];
    
    
    
    
}


@end
